﻿using System.Windows;
using System.Windows.Controls;
using System;

namespace Silverlight.InputCtrl
{
    public class RequiredValidator : ValidatorBase
    {

        public string InitialValue
        {
            get { return (string)GetValue(InitialValueProperty); }
            set { SetValue(InitialValueProperty, value);}
        }

        public static readonly DependencyProperty InitialValueProperty =
            DependencyProperty.Register("InitialValue", typeof(string), typeof(RequiredValidator), new PropertyMetadata(""));

        public override bool Validate()
        {
            base.IsValidResult = true;
            FrameworkElement _elemValidate = base.ElementValidator;
            if (_elemValidate != null && Enabled)
            {
                base.IsValidResult = false;
                string value =  ValidatorCommon.GetValueText(_elemValidate,base.PropertyToValidate);
                if (!String.IsNullOrEmpty(value))
                {
                    value = value.Trim();
                    if (InitialValue != value)
                    {
                        base.IsValidResult = true;
                    }
                }
            }
            return base.IsValidResult;
        }
    }
}
